<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2021 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>The &lt;table&gt; Element</title>
  <link rel="stylesheet" type="text/css" href="../mbgstyle.css" />
</head>
<body>
<h1>The &lt;table&gt; Element</h1>
<p>The &lt;table&gt; element is used to select a table in the database for
introspection.  Selected tables will cause the following objects to be generated
for each table:</p>
<ul>
  <li>A MyBatis formatted SQL Map file</li>
  <li>A set of classes that form the "model" of the table including:
    <ul>
      <li>A class to match the primary key of the table (if the table
          has a primary key).</li>
      <li>A class to match the fields in the table that are not in the
          primary key, and non BLOB fields.  This class will extend the
          primary key if there is one.</li>
      <li>A class to hold any BLOB fields in the table, if there are any.
          This class will extend one of the two previous classes depending on the
          configuration of the table.</li>
      <li>A class that is used to generate dynamic where clauses in the
          different "by example" methods (selectByExample, deleteByExample).</li>
    </ul>
  </li>
  <li>(Optionally) A MyBatis mapper interface</li>
</ul>
<p>At least one &lt;table&gt; element must be specified as a required child element
of the <a href="context.html">&lt;context&gt;</a> element.
You can specify unlimited table elements.</p>

<h2>Database Identifiers</h2>
<p>MyBatis Generator (MBG) tries to deal with the case sensitivity of database identifiers automatically.
In most cases, MBG is able to find tables regardless of what you
specify for <code>catalog</code>, <code>schema</code>, and <code>tableName</code>
attributes.  MBG's process follows these steps:</p>
<ol>
  <li>If either of the <code>catalog</code>, <code>schema</code>, or
      <code>tableName</code> attributes contain a space, then MBG will
      look for tables based on the exact case specified.  In this case, MBG
      will automatically delimit the table identifiers in the generated SQL.</li>
  <li>Else if the database reports that identifiers are stored in upper case,
      MBG will automatically convert any table identifier to upper case.</li>
  <li>Else if the database reports that identifiers are stored in lower case,
      MBG will automatically convert any table identifier to lower case.</li>
  <li>Else MBG will look for tables based on the exact case specified.</li>
</ol>
<p>In most cases, this process works perfectly.  However, there are cases where it will
fail.  For example, suppose you create a table like this:</p>
<pre>
  create table "myTable" (
     ...some columns
  )
</pre>

<p>Because the table name is delimited, most databases will create the
table with the exact case specified - even if the database normally stores
identifiers in upper case.  In this instance, you should specify the attribute
<code>delimitIdentifiers="true"</code> in the table configuration.</p>

<h2>Required Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">tableName</td>
    <td>The name of the database table (not including the schema or catalog).
      The specified value can contain SQL wildcards if so desired.
    </td>
  </tr>
</table>

<h2>Optional Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">schema</td>
    <td>The database schema - not required if your database does not use schemas,
        or if there is a default schema.
      The specified value can contain SQL wildcards if so desired.
    </td>
  </tr>
  <tr>
    <td valign="top">catalog</td>
    <td>The database catalog - not required if your database does not use catalogs,
        or if there is a default catalog.</td>
  </tr>
  <tr>
    <td valign="top">alias</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        If specified, this value will be used to alias the table and all column names in
        any generated SQL select statement.  Column names will be aliased with the pattern
        alias_actualColumnName.</td>
  </tr>
  <tr>
    <td valign="top">domainObjectName</td>
    <td>The base name from which generated object names will be generated.
        If not specified, MBG will generate a name automatically based on
        the tableName.  The name (either specified here, or generated
        automatically) will be used to compute generated domain class names
        and DAO class names.
        <p>You can specify a package fragment in the domain object name.  For example,
           if you specify <code>foo.Bar</code> then the domain object will be
           <code>Bar</code> and package <code>foo</code> will be appended
           to the target package specified in the generator configurations.</p>
    </td>
  </tr>
  <tr>
    <td valign="top">mapperName</td>
    <td>The name of the MyBatis3 generated mapper class and XML file.
        If not specified, the name will be whatever the domain object name is, plus the
        word &quot;Mapper&quot;.
        <p>You can specify a package fragment in the mapper name.  For example,
           if you specify <code>foo.BarMapper</code> then the mapper will be
           <code>BarMapper</code> and package <code>foo</code> will be appended
           to the target package specified in the generator configurations.</p>
        <p>Since version 1.3.4</p>
    </td>
  </tr>
  <tr>
    <td valign="top">sqlProviderName</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        The name of the MyBatis3 generated SQL provider class (which may or may not be generated
        based on the configuration).
        If not specified, the name will be whatever the domain object name is, plus the
        word &quot;SqlProvider&quot;.
        <p>You can specify a package fragment in the SQL provider name.  For example,
           if you specify <code>foo.BarSqlProvider</code> then the SQL provider will be
           <code>BarSqlProvider</code> and package <code>foo</code> will be appended
           to the target package specified in the generator configurations.</p>
        <p>Since version 1.3.4</p>
    </td>
  </tr>
  <tr>
    <td valign="top">enableInsert</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
       Signifies whether an insert statement should be generated.
    <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableSelectByPrimaryKey</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether a select by primary key statement should be generated.
        Regardless of this setting, the statement will not be generated if the
        table does not have a primary key.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableSelectByExample</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether a select by example statement should be generated.
        This statement enables many different dynamic queries to be generated at run time.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableUpdateByPrimaryKey</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether an update by primary key statement should be generated.
        Regardless of this setting, the statement will not be generated if the
        table does not have a primary key.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableDeleteByPrimaryKey</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether an delete by primary key statement should be generated.
        Regardless of this setting, the statement will not be generated if the
        table does not have a primary key.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableDeleteByExample</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether a delete by example statement should be generated.
        This statement enables many different dynamic deletes to be generated at run time.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableCountByExample</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether a count by example statement should be generated.
        This statement will return the number of rows in a table that match
        an example.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">enableUpdateByExample</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        Signifies whether an update by example statement should be generated.
        This statement will update rows in a table that match
        an example.
        If true, an update by example "selective" statement will also be generated.
        The "selective" statement will only update columns where the corresponding
        value in the record parameter is non-null.
        <p>The default is <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">selectByPrimaryKeyQueryId</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        This value will be added to the select list of the select by primary key statement
        in this form: "'&lt;value&gt;' as QUERYID".
        This can be useful for identifying queries in DBA tracing tools at run time.
        If you use thus value, you should specify a unique id for every different query
        generated by MBG.</td>
  </tr>
  <tr>
    <td valign="top">selectByExampleQueryId</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        This value will be added to the select list of the select by example statement
        in this form: "'&lt;value&gt;' as QUERYID".
        This can be useful for identifying queries in DBA tracing tools at run time.
        If you use thus value, you should specify a unique id for every different query
        generated by MBG.</td>
  </tr>
  <tr>
    <td valign="top">modelType</td>
    <td>
      <i>This attribute is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
      This attribute is used to override the default model type if you desire
      to do so for this table.  If not specified, MBG will generate domain
      objects based on the context default model type.
      The model type defines how MBG will generate domain classes.  With some
      model types MBG will generate a single domain class for each table,
      with others MBG may generate different classes depending on the structure
      of the table.  The property supports these values:
      <table>
        <tr>
          <th valign="top">conditional</th>
          <td>This model is similar to the hierarchical model except that a separate
              class will not be generated if that separate class would only contain
              one field.  So if a table has only one primary key field, that field
              will be merged into the base record class.</td>
        </tr>
        <tr>
          <th valign="top">flat</th>
          <td>This model generates only one domain class for any table.  The class
              will hold all fields in the table.</td>
        </tr>
        <tr>
          <th valign="top">hierarchical</th>
          <td>This model will generate a primary key class if the table has
              a primary key, another class that holds any BLOB columns in the table, and
              another class that holds the remaining fields.  There is an appropriate
              inheritance relationship between the classes.</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td valign="top">escapeWildcards</td>
    <td>Signifies whether SQL wildcards ('_' and '%') in the schema and tableName should
        be escaped when searching for columns.  This is required by some drivers if the
        schema or tableName includes an SQL wildcard (for example, if a table name is
        MY_TABLE, some drivers require that the underscore character be escaped).
        <p>The default is <i>false</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">delimitIdentifiers</td>
    <td>Signifies whether MBG should use the exact case specified when searching
        for tables and then delimit the identifiers in the generated SQL.  See the
        discussion above for more details.
        <p>The delimiter characters are specified on the
        <a href="context.html">&lt;context&gt;</a> element.</p>
        <p>The default is <i>false</i> unless the <code>catalog</code>,
        <code>schema</code>, or <code>tableName</code> attributes
        contain a space, then <i>true</i>.</p></td>
  </tr>
  <tr>
    <td valign="top">delimitAllColumns</td>
    <td>Signifies whether MBG should add delimiters to all column names in the generated
        SQL.  This is an alternative to coding a <code>&lt;columnOverride&gt;</code>
        for every column
        specifying that the column should be delimited.  This is useful for databases
        like PostgreSQL that are case sensitive with identifiers.
        <p>The delimiter characters are specified on the
        <a href="context.html">&lt;context&gt;</a> element.</p>
        <p>The default is <i>false</i>.</p></td>
  </tr>
</table>

<h2>Child Elements</h2>
<ul>
  <li><a href="property.html">&lt;property&gt;</a> (0..N)</li>
  <li><a href="generatedKey.html">&lt;generatedKey&gt;</a> (0 or 1)</li>
  <li><a href="domainObjectRenamingRule.html">&lt;domainObjectRenamingRule&gt;</a> (0 or 1)</li>
  <li><a href="columnRenamingRule.html">&lt;columnRenamingRule&gt;</a> (0 or 1)</li>
  <li><a href="columnOverride.html">&lt;columnOverride&gt;</a> (0..N)</li>
  <li><a href="ignoreColumn.html">&lt;ignoreColumn&gt;</a> (0..N)</li>
</ul>

<h2>Supported Properties</h2>
<p>This table lists the properties of the default SQL Map generators that can be
specified with the <a href="property.html">&lt;property&gt;</a> child element:</p>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Property Name</th>
    <th>Property Values</th>
  </tr>
  <tr>
    <td valign="top">constructorBased</td>
    <td><i>This property is ignored is the target runtime is "MyBatis3Kotlin"</i><br/>
      This property is used to select whether MyBatis Generator will generate a constructor
      for the class that accepts a value for each field in the class.  Also, the SQL result map
      will be built to use the constructor rather than the "setter" for each field.
      <p>This property is ignored (and forced "true") if the "immutable" property
         is set "true".</p>
      <p><i>The default value is false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">dynamicSqlSupportClassName</td>
    <td><i>This property is ignored unless the target runtime is "MyBatis3DynamicSQL" or "MyBatis3Kotlin"</i><br/>
        The name of the generated MyBatis Dynamic SQL support class.
        If not specified, the name will be whatever the domain object name is, plus the
        word &quot;DynamicSqlSupport&quot;.
        <p>You can specify a package fragment in the support class name.  For example,
            if you specify <code>foo.BarSqlSupport</code> then the SQL provider will be
            <code>BarSqlSupport</code> and package <code>foo</code> will be appended
            to the package specified in the generator configuration.</p>
        <p>Since version 1.4.1</p>
    </td>
  </tr>
  <tr>
    <td valign="top">ignoreQualifiersAtRuntime</td>
    <td>If true, then
        MBG will not add the schema or catalog to the table name in the generated SQL.
        This is useful if you have tables with the same name in several schemas -
        you can use MBG to generate objects based on the table in one schema,
        but not include the schema for runtime.<p/>
        <p><i>The default value is false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">immutable</td>
    <td><i>This property is ignored is the target runtime is "MyBatis3Kotlin"</i><br/>
      This property is used to select whether MBG will generate immutable
      model classes - this means that the classes will not have "setter" methods and
      the constructor will accept values for each field in the class.
      <p>If true, this forces the model classes to be built with paramterized constructors
         regardless of the value of the "constructorBased" property.</p>
      <p><i>The default value is false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">modelOnly</td>
    <td>
      This property is used to select whether MBG will only generate
      model classes for a table.
      <p>If true, then a Java client will not be generated.
      If an &lt;sqlMapGenerator&gt; is configured and this property is set true then
      MBG will only generate result map elements in the SQL Mapper XML file for this table.</p>
      <p>If true, then this value overrides any of the "enable*" attributes on the &lt;table&gt;
      element - no CRUD methods will be generated.</p>
      <p><i>The default value is false.</i></p>
    </td>
  </tr>
  <tr>
    <td valign="top">rootClass</td>
    <td><i>This attribute is ignored if the target runtime is "MyBatis3Kotlin"</i><br/>
      This property can be used to specify a root class for all generated
      Java model objects.  MBG will specify this value as the super class
      of the primary key object, if the table has a primary key, or the
      record object otherwise.  The value specified in this property will override
      the <code>rootClass</code> property set on the Java Model Generator
      configuration if any is set.
      <p><b>Important:</b> If MBG is able to load the root class, it
       will not override a property in the root class that exactly matches a
       property that would normally be generated.
       An exact match of a property is defined as follows</p>
       <ul>
         <li>Property name matches exactly</li>
         <li>Property is of the same type</li>
         <li>Property has a "getter" method</li>
         <li>Property has a "setter" method</li>
       </ul>
      <p>If specified, the value of this property should be a fully qualified
       class name (like com.mycompany.MyRootClass).</p></td>
  </tr>
  <tr>
    <td valign="top">rootInterface</td>
    <td><i>This property is ignored if the target runtime is "MyBatis3Kotlin"</i><br/>
      This property can be used to specify a super interface for all generated
      DAO interface objects. The value specified in this property will override
      the <code>rootInterface</code> property set on the Java Client Generator
      configuration if any is set.
      <p><b>Important:</b> MBG does not verify that the interface exists, or is a
       valid Java interface.</p>
      <p>If specified, the value of this property should be a fully qualified
       interface name (like com.mycompany.MyRootInterface).</p></td>
  </tr>
  <tr>
    <td valign="top">runtimeCatalog</td>
    <td>If you specify a value for this property, than MBG will use that
        value as the catalog in the generated SQL rather than the <code>catalog</code>
        as configured above.
        This is useful if you want to generate code against one catalog, but
        want to use a different catalog at runtime.</td>
  </tr>
  <tr>
    <td valign="top">runtimeSchema</td>
    <td>If you specify a value for this property, than MBG will use that
        value as the schema in the generated SQL rather than the <code>schema</code>
        as configured above.
        This is useful if you want to generate code against one schema, but
        want to use a different schema at runtime.</td>
  </tr>
  <tr>
    <td valign="top">runtimeTableName</td>
    <td>If you specify a value for this property, than MBG will use that
        value as the table name in the generated SQL rather than the <code>tableName</code>
        as configured above.
        This is especially useful on Oracle if you want to generate objects to use
        a public synonym.  In that case, you will need to generate the objects against the
        actual table that the synonym points to, then specify the synonym name in
        this property.  You should also specify the <code>ignoreQualifiersAtRuntime</code>
        property in most cases with public synonyms.</td>
  </tr>
  <tr>
    <td valign="top">selectAllOrderByClause</td>
    <td>This property can be used to specify an order by clause that will be added to
        the <code>selectAll</code> method.  This is only applicable if you are using the
        <code>MyBatis3Simple</code> target runtime.  MBG will prepend <code>order by</code>
        to anything you specify in this property, so the property should contain
        a column list only (e.g <code>ID1, ID2</code> or <code>ID1 desc, ID2 asc</code>)
        </td>
  </tr>
  <tr>
    <td valign="top">trimStrings</td>
    <td><i>This attribute is ignored is the target runtime is "MyBatis3Kotlin"</i><br/>
      <p>This property is used to select whether MyBatis Generator adds code to trim
      the white space from character fields returned from the database.
      This can be useful if your database stores data in CHAR fields rather than
      VARCHAR fields.  When true, MyBatis Generator will insert code to trim character fields.
      Can be overridden with the <code>trimStrings</code> property in a &lt;columnOverride&gt; 
      configuration. This property value overrides the property if specified at the 
      <a href="javaModelGenerator.html">&lt;javaModelGenerator&gt;</a> level
      and can be overridden for fields/columns using the property in a 
      <a href="columnOverride.html">&lt;columnOverride&gt;</a> element.</p>
      <p><i>The default value is inherited from the 
      <a href="javaModelGenerator.html">&lt;javaModelGenerator&gt;</a>, otherwise false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">useActualColumnNames</td>
    <td>If true, then
        MBG will use column names as returned from the database metadata as the properties
        of the generated domain objects.  If false (default), MBG will attempt to camel
        case the returned names.  In either event, the name can be specified explicitly by the
        &lt;columnOverride&gt; element in which case this property will be ignored for the
        specified column.
        <p>For example, suppose a table contains a column START_DATE.  If the value of
        this property is "true", then MBG will generate the property name
        as <code>START_DATE</code> - meaning that the getters and setters for the value will be
        <code>getSTART_DATE()</code> and <code>setSTART_DATE()</code>.
        If the value of this property is false, then MBG will
        generate the property name as <code>startDate</code> - meaning that the
        getters and setters for the value will be <code>getStartDate()</code> and
        <code>setStartDate()</code>.</p>
        <p><i>The default value is false.</i></p></td>
  </tr>
  <tr>
    <td valign="top">useColumnIndexes</td>
    <td><i>This property is ignored is the target runtime is "MyBatis3DynamicSql" or "MyBatis3Kotlin"</i><br/>
        If true, then MBG will generate resultMaps that use column index rather than
        column name in the result mappings.  This is useful when a table has column names
        differentiated only by the case of the name (e.g. "first name" and "First Name").
        There is a slight performance benefit with this support also.<p/>
        <p><i>The default value is false.</i></p>
        <p><b>Important Note:</b> This property is not supported if the target runtime is
            for MyBatis version 3.</p></td>
  </tr>
  <tr>
    <td valign="top">useCompoundPropertyNames</td>
    <td>If true, then
        MBG will use generate property names by contatenating the column name with the
        column reparks.  This can be usefull in databases created by 4th generation languages
        where the column names are generated (e.g. FLD2237), but the remarks contain useful
        information (e.g. "customer id").  In this case, MBG will generate a property
        name of FLD2237_CustomerId.
        <p><i>The default value is false.</i></p></td>
  </tr>
</table>

<h2>Example</h2>
<p>This element specifies that we always want to generate code for
a table called MYTABLE in schema MYSCHEMA.  We also want to ignore
a column called "fred" in the table, and we want to override the
column "BEG_DATE" so that the generated property name will be "startDate".</p>
<pre>
&lt;table tableName="MYTABLE" schema="MYSCHEMA"&gt;
  &lt;ignoreColumn column="fred"/&gt;
  &lt;columnOverride column="BEG_DATE" property="startDate"/&gt;
&lt;/table&gt;
</pre>

</body>
</html>
